import $service from '../../../../../service.js';
var doctor_id;
var that;
var notice_id;
var prescription_id;
var inquiry_patient_id;
Page({
    data:{
       active : true,
       notice_type:'',
       prescriptionMap:{},
       prescriptionList:[],
       inquiryMap:{},
       type:0,
    },
    onLoad(e){
        if(e.type == 1){//我的消息
           this.data.notice_type = e.notice_type;
           notice_id = e.notice_id;
           var title = '消息详情'
        }else if(e.type == 2){//搜索-处方详情
            prescription_id = e.prescription_id
            var title = '处方详情'
        }else if(e.type == 3){//搜索-患者详情
            let info = JSON.parse($service.getStore('patientInfo'));
            if (info.diagnosisDescribe) {
                 info.diagnosisDescribe = JSON.parse(info.diagnosisDescribe).map(item => item.diagnosis).join();
            }
            this.setData({
                inquiryMap: info
            })
            var title = '患者详情'
        }
        wx.setNavigationBarTitle({
            title: title
        })
        this.setData({
            notice_type : this.data.notice_type,
            type:e.type
        }) 
    },
    onShow(){
        if(this.data.type == 1){//我的消息详情
           this.publicUtil_getNoticeDetails()
        }else if(this.data.type == 2){//搜索-处方详情
            this.publicUtil_getInquiryLogPrescriptionDetails()
        }
        
    },
    //我的消息详情
    publicUtil_getNoticeDetails:function(){
        var jsonData ={
            "notice_id" : notice_id
        }
        var jsonAjax = {
            "url": "publicUtil_getNoticeDetails.do",
            "jsonData": jsonData,
        }
        $service.getAjaxData(jsonAjax, this.publicUtil_getNoticeDetails_back);
    },
    publicUtil_getNoticeDetails_back:function(jsonBack){
        var data=$service.strToJson(jsonBack.data).data; 
        var noticeMap = data.noticeMap;
        if(this.data.notice_type == 2){
            this.data.prescriptionMap = data.prescriptionMap;
            this.data.prescriptionList =  this.data.prescriptionMap.prescriptionList;
            this.data.inquiryMap = data.inquiryMap;
        }
        this.setData({
            noticeMap : noticeMap,
            prescriptionMap : this.data.prescriptionMap,
            prescriptionList : this.data.prescriptionList,
            inquiryMap : this.data.inquiryMap
        })
    },
    //搜索-处方详情
    publicUtil_getInquiryLogPrescriptionDetails:function(){
        var jsonData ={
            "prescription_id" : prescription_id
        }
        var jsonAjax = {
            "url": "publicUtil_getInquiryLogPrescriptionDetails.do",
            "jsonData": jsonData,
        }
        $service.getAjaxData(jsonAjax, this.publicUtil_getInquiryLogPrescriptionDetails_back);
    },
    publicUtil_getInquiryLogPrescriptionDetails_back:function(jsonBack){
        var data=$service.strToJson(jsonBack.data).data; 
        var doctorMap = data.doctorMap;
        var prescriptionMap = data.prescriptionMap;////处方内容
        var prescriptionList = prescriptionMap.prescriptionList;//处方
        var inquiryMap = data.inquiryMap;//诊断信息
        this.setData({
            prescriptionMap : prescriptionMap,
            prescriptionList :prescriptionList,
            inquiryMap : inquiryMap
        })
    },
})